import Cookie from 'js-cookie'
export default (router, store) => {
    router.beforeEach((to, from, next) => {
      if (window.top != window.self) {
        const token = to.query.token;
        if (token) {
          Cookie.set("token", token);
          localStorage.setItem('loginToken',token)
        }
    }
      if (localStorage.getItem('loginToken')) {
        store.dispatch('routerTabs/addHistoryRoutes', to);
        next();
      } else if (to.name === 'login') {
            next()
        } else if (to.name === 'home' && !localStorage.getItem('loginToken')) {
          router.replace({ path: '/login' })
        }
        // console.log(to, from);

        // to do sth....
    });
}
